import { getLocation } from '@/util/uniapi'

export default {
  data() {
    return {
      title: "Hello",
    };
  },
  onLoad() {
    // #ifdef  H5
    uni.showToast({
      title: "不支持h5环境！！！",
      icon: "none",
      duration:10000000
    });
    // #endif
   },
  methods: {
    //打开地图
    getAddress() {
      uni.chooseLocation({
        success: function (res) {
          console.log("位置名称：" + res.name);
          console.log("详细地址：" + res.address);
          console.log("纬度：" + res.latitude);
          console.log("经度：" + res.longitude);
        },
      });
    },
    openMap(){
      uni.openLocation({
        longitude: 121.48941,
        latitude: 31.40527,
        name: '上海市',
        address: '上海市',
        scale: 14
      })
    },
    //获取定位
    async getLocation() {
      if (this.$wechat && this.$wechat.isWechat()) {
        // 微信h5api
        let res = await this.$wechat.getLocation();
        uni.showToast({
          title: "定位成功，详见打印！",
          icon: "none",
        });
        console.log(res)
      } else {
        // 小程序
        let res = await getLocation();
        uni.showToast({
          title: "定位成功，详见打印！",
          icon: "none",
        });
        console.log(res)
      }

    },
  },
};